package com.itbaima.pojo.entity;

import com.itbaima.exception.UserRoleException;
import com.itbaima.message.MessageConstant;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "users")
    public class User {

        @Id
        @Column(name = "user_id")
        private Integer user_id; // 用户ID（主键，自增）

        private String name;

        private String username; // 用户名

        private String password; // 用户密码

        private String role; // 用户身份（"staff" 或 "manager"）

    public void setRole(String role) {
        // 校验 role 是否为 "staff" 或 "manager"
        if (!"staff".equals(role) && !"manager".equals(role)) {
            throw new UserRoleException(MessageConstant.USER_ROLE_ERROR);
        }
        this.role = role;
    }


}
